package com.orange.community.util;

import com.orange.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * @author GaryGyp
 * @Description 起容器的作用，持有用户的信息，用于带起 session 对象，获取当前登录的用户
 */
@Component
public class HostHolder {

    // 以线程为key来存取值
    private ThreadLocal<User> users = new ThreadLocal<>();

    public void setUser(User user) {
        users.set(user);
    }

    public User getUser() {
        return users.get();
    }

    public void clear() {
        users.remove();
    }

}
